﻿package mortal.game.view.copy.QuestionCopy.data
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import mortal.game.cache.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.vip.*;

    public class QuestionCopyConfig extends Object
    {
        public var questionOjb:Object;
        public var questionRewardArr:Array;
        public var enterShowRewardArr:Array;
        public var wordLevelAddExpArr:Array;
        private var _timeStr:String = "";
        private var _doubleTotal:int = -1;
        private var _threeTotal:int = -1;
        private static var _instance:QuestionCopyConfig;

        public function QuestionCopyConfig()
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_question.json");
            this.writeQuestion(_loc_1);
            var _loc_2:* = ConfigManager.instance.getJSONByFileName("t_question_rewards.json");
            this.writeReward(_loc_2);
            return;
        }// end function

        private function writeQuestion(param1:Object) : void
        {
            var _loc_2:Object = null;
            this.questionOjb = {};
            for each (_loc_2 in param1)
            {
                
                this.questionOjb[_loc_2.questionId] = _loc_2;
            }
            return;
        }// end function

        private function writeReward(param1:Object) : void
        {
            var _loc_2:TQuestionRewards = null;
            var _loc_3:Object = null;
            this.questionRewardArr = param1 as Array;
            this.wordLevelAddExpArr = new Array();
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TQuestionRewards();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (_loc_2.type == 9)
                {
                    this.wordLevelAddExpArr.push(_loc_2);
                }
            }
            return;
        }// end function

        public function getTotal() : Array
        {
            var _loc_4:Object = null;
            var _loc_5:String = null;
            var _loc_6:Array = null;
            if (this.questionRewardArr == null)
            {
                return [0, 0];
            }
            var _loc_1:int = 0;
            while (_loc_1 < this.questionRewardArr.length)
            {
                
                _loc_4 = this.questionRewardArr[_loc_1];
                if (_loc_4.type == 3)
                {
                    this._doubleTotal = this.getTimes(_loc_4.times, 0);
                    this._threeTotal = this.getTimes(_loc_4.times, 1);
                }
                _loc_1++;
            }
            var _loc_2:* = VipUtil.getVipMinLevelByType(QuestionCopyDataUtil.vipType);
            var _loc_3:* = Cache.instance.vip.level;
            if (_loc_3 < _loc_2)
            {
                this._threeTotal = 0;
            }
            else
            {
                _loc_5 = VipConfig.instance.getValueByTypeAndLv(QuestionCopyDataUtil.vipType, _loc_3);
                _loc_6 = _loc_5.split("#");
                if (_loc_6.length > 1)
                {
                    this._threeTotal = parseInt(_loc_6[1]);
                }
                else
                {
                    this._threeTotal = 0;
                }
            }
            return [this._doubleTotal, this._threeTotal];
        }// end function

        private function getTimes(param1:String, param2:int) : int
        {
            var _loc_3:* = param1.split("&");
            var _loc_4:* = _loc_3[param2].split("#");
            var _loc_5:* = int(_loc_4[1]);
            return _loc_5;
        }// end function

        public function getWorldLevelRewardsObj() : Array
        {
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_1:Array = [];
            var _loc_2:* = Cache.instance.publicCache.worldLevel;
            var _loc_3:int = 0;
            while (_loc_3 < this.questionRewardArr.length)
            {
                
                _loc_4 = this.questionRewardArr[_loc_3];
                _loc_5 = int(_loc_4.worldLevelMin);
                _loc_6 = int(_loc_4.worldLevelMax);
                if (_loc_5 <= _loc_2 && _loc_2 <= _loc_6 && _loc_4.type == 2)
                {
                    _loc_1.push(_loc_4);
                }
                _loc_3++;
            }
            _loc_1.sortOn(["scoreMin"], [Array.NUMERIC]);
            return _loc_1;
        }// end function

        public function getRewardItems(param1:String) : Array
        {
            var _loc_5:String = null;
            var _loc_6:Array = null;
            var _loc_7:SPlayerItem = null;
            var _loc_2:Array = [];
            var _loc_3:* = param1.split("&");
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_5 = _loc_3[_loc_4];
                _loc_6 = _loc_5.split("#");
                _loc_7 = new SPlayerItem();
                if (_loc_6.length == 3)
                {
                    _loc_7.itemCode = int(_loc_6[1]);
                    _loc_7.itemAmount = int(_loc_6[2]);
                }
                else
                {
                    _loc_7.itemCode = int(_loc_6[0]);
                    _loc_7.itemAmount = int(_loc_6[1]);
                }
                if (_loc_7.itemCode == 0)
                {
                }
                else
                {
                    _loc_2.push(_loc_7);
                }
                _loc_4++;
            }
            return _loc_2;
        }// end function

        public function getRewardInfoByTypeAndLevel(param1:int, param2:int) : Object
        {
            var _loc_3:Object = null;
            for each (_loc_3 in this.questionRewardArr)
            {
                
                if (_loc_3.type == param1 && _loc_3.times == param2)
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function getRewardInfoByTypeAndScoreMax(param1:int, param2:int) : Object
        {
            var _loc_3:Object = null;
            for each (_loc_3 in this.questionRewardArr)
            {
                
                if (_loc_3.type == param1 && _loc_3.scoreMax == param2)
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function getRewardInfoByType(param1:int) : Array
        {
            var _loc_3:Object = null;
            var _loc_2:Array = [];
            for each (_loc_3 in this.questionRewardArr)
            {
                
                if (_loc_3.type == param1)
                {
                    _loc_2.push(_loc_3);
                }
            }
            return _loc_2;
        }// end function

        public function getRewardsByTypeAndTimes(param1:int, param2:int) : Array
        {
            var _loc_4:Object = null;
            var _loc_3:Array = [];
            for each (_loc_4 in this.questionRewardArr)
            {
                
                if (_loc_4.type == param1 && _loc_4.times == param2)
                {
                    _loc_3.push(_loc_4);
                }
            }
            return _loc_3;
        }// end function

        public static function instance() : QuestionCopyConfig
        {
            if (_instance == null)
            {
                _instance = new QuestionCopyConfig;
            }
            return _instance;
        }// end function

    }
}
